package com.ruoyi.teaching.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.teaching.dto.InterviewQuestionMasteryInquiryDTO;
import com.ruoyi.teaching.dto.QueryInterviewMasteryDTO;
import com.ruoyi.teaching.dto.vo.InterviewDetailVO;
import com.ruoyi.teaching.dto.vo.InterviewMasteryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.teaching.mapper.YaInterviewMasteryMapper;
import com.ruoyi.teaching.domain.YaInterviewMastery;
import com.ruoyi.teaching.service.IYaInterviewMasteryService;

/**
 * 面试掌握情况记录Service业务层处理
 *
 * @author ruoyi
 * @date 2025-09-04
 */
@Service
public class YaInterviewMasteryServiceImpl implements IYaInterviewMasteryService {
  @Autowired
  private YaInterviewMasteryMapper yaInterviewMasteryMapper;

  /**
   * 查询面试掌握情况记录
   *
   * @param id 面试掌握情况记录主键
   * @return 面试掌握情况记录
   */
  /*@Override
  public YaInterviewMastery selectYaInterviewMasteryById(Long id) {
    return yaInterviewMasteryMapper.selectYaInterviewMasteryById(id);
  }*/
  /**
   * 查询面试掌握情况记录
   *
   * @param id 面试掌握情况记录主键
   * @return 面试掌握情况记录
   */
  @Override
  public InterviewMasteryVO selectYaInterviewMasteryById(Long id) {
    List<QueryInterviewMasteryDTO> yaInterviewMasteryDTOS = yaInterviewMasteryMapper.selectYaInterviewMasteryById(id);
    // 处理数据
    InterviewMasteryVO interviewMasteryVO = new InterviewMasteryVO();
    ArrayList<InterviewDetailVO> interviewDetailVOS = new ArrayList<>();
    yaInterviewMasteryDTOS.stream().forEach(e -> {
      if(e.getId()!=null){
        String communicationMastery = e.getCommunicationMastery();
        // 设置沟通情况
        interviewMasteryVO.setCommunicationInterview_mastery(communicationMastery);
      }
      InterviewDetailVO interviewDetailVO = new InterviewDetailVO();
      interviewDetailVO.setStage(e.getStage());
      interviewDetailVO.setAnswer(e.getAnswer());
      interviewDetailVO.setImportance(e.getImportance());
      interviewDetailVO.setHisDegree(e.getDegree());
      interviewDetailVO.setScore(e.getScore());
      interviewDetailVO.setLastCreateBy(e.getCreateBy());
      interviewDetailVO.setQuestion(e.getQuestion());
      interviewDetailVOS.add(interviewDetailVO);
    });
    interviewMasteryVO.setInterview_masteryDetailList(interviewDetailVOS);
    return interviewMasteryVO;
  }

  /**
   * 查询面试掌握情况记录列表
   *
   * @param yaInterviewMastery 面试掌握情况记录
   * @return 面试掌握情况记录
   */
  @Override
  public List<YaInterviewMastery> selectYaInterviewMasteryList(YaInterviewMastery yaInterviewMastery) {
    return yaInterviewMasteryMapper.selectYaInterviewMasteryList(yaInterviewMastery);
  }

  /**
   * 新增面试掌握情况记录
   *
   * @param yaInterviewMastery 面试掌握情况记录
   * @return 结果
   */
  @Override
  public int insertYaInterviewMastery(YaInterviewMastery yaInterviewMastery) {
    yaInterviewMastery.setCreateBy("admin");
    yaInterviewMastery.setCreateTime(DateUtils.getNowDate());
    return yaInterviewMasteryMapper.insertYaInterviewMastery(yaInterviewMastery);
  }

  /**
   * 修改面试掌握情况记录
   *
   * @param yaInterviewMastery 面试掌握情况记录
   * @return 结果
   */
  @Override
  public int updateYaInterviewMastery(YaInterviewMastery yaInterviewMastery) {
    yaInterviewMastery.setUpdateTime(DateUtils.getNowDate());
    return yaInterviewMasteryMapper.updateYaInterviewMastery(yaInterviewMastery);
  }

  /**
   * 批量删除面试掌握情况记录
   *
   * @param ids 需要删除的面试掌握情况记录主键
   * @return 结果
   */
  @Override
  public int deleteYaInterviewMasteryByIds(Long[] ids) {
    return yaInterviewMasteryMapper.deleteYaInterviewMasteryByIds(ids);
  }

  /**
   * 删除面试掌握情况记录信息
   *
   * @param id 面试掌握情况记录主键
   * @return 结果
   */
  @Override
  public int deleteYaInterviewMasteryById(Long id) {
    return yaInterviewMasteryMapper.deleteYaInterviewMasteryById(id);
  }

  @Override
  public List<YaInterviewMastery> selectYaInterviewMasteryListQuery(InterviewQuestionMasteryInquiryDTO interviewQuestionMasteryInquiryDTO) {
    return yaInterviewMasteryMapper.selectYaInterviewMasteryListQuery(interviewQuestionMasteryInquiryDTO);
  }
}
